/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package reportes;

import com.gestion.dao.FabricaDAO;
import com.gestion.modelo.dominio.EstadosPedido;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.util.JRLoader;
import net.sf.jasperreports.view.JasperViewer;

/**
 *
 * @author usuario
 */
public class Reporte {

    FabricaDAO fdao;

    public Reporte() {
        fdao = new FabricaDAO();
    }

    public void mostrarReporte(EstadosPedido estado) {
        JasperReport masterReport = null;
        try {
            Map parametro = new HashMap();
            parametro.put("estado", "0");

            masterReport = (JasperReport) JRLoader.loadObject(System.getProperty("user.dir")
                    + "/src/Reportes/Reporte" + estado.toString() + ".jasper");

            JasperPrint jasperPrint = JasperFillManager.fillReport(masterReport, parametro, FabricaDAO.getConnection());

            JasperViewer jviewer = new JasperViewer(jasperPrint, false);
            jviewer.setTitle("Gestión Entrega");
            jviewer.setVisible(true);

        } catch (JRException ex) {
            Logger.getLogger(Reporte.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            System.out.println(ex.getMessage());
        }
    }

    public void mostrarReporteCantidadProductos() {
        JasperReport masterReport = null;
        try {
            Map parametro = new HashMap();
            parametro.put("estado", "0");

            masterReport = (JasperReport) JRLoader.loadObject(System.getProperty("user.dir")
                    + "/src/Reportes/ReporteCantidadProductos.jasper");

            JasperPrint jasperPrint = JasperFillManager.fillReport(masterReport, parametro, FabricaDAO.getConnection());

            JasperViewer jviewer = new JasperViewer(jasperPrint, false);
            jviewer.setTitle("Gestión Entrega");
            jviewer.setVisible(true);

        } catch (JRException ex) {
            Logger.getLogger(Reporte.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            System.out.println(ex.getMessage());
        }
    }

    public void mostrarReporteProductoAEscasear() {
        JasperReport masterReport = null;
        try {
            Map parametro = new HashMap();
            parametro.put("estado", "0");

            masterReport = (JasperReport) JRLoader.loadObject(System.getProperty("user.dir")
                    + "/src/Reportes/ReporteProductoAEscasear.jasper");

            JasperPrint jasperPrint = JasperFillManager.fillReport(masterReport, parametro, FabricaDAO.getConnection());

            JasperViewer jviewer = new JasperViewer(jasperPrint, false);
            jviewer.setTitle("Gestión Entrega");
            jviewer.setVisible(true);

        } catch (JRException ex) {
            Logger.getLogger(Reporte.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            System.out.println(ex.getMessage());
        }
    }
}
